<?php
require_once('../../config.php');
Doctrine::loadModels('../../models');

if ($_REQUEST["agent_id"]) 
{
	$agent_id = strip_tags($_REQUEST["agent_id"]);
	//file_put_contents  ( "param_id.txt", $agent_id);	
	
	$query = $db_query = sprintf("SELECT a.agent_id, a.name_short, a.name_full, 
				a.agent_type_id, a.date_start, a.date_end,
        		r.resource_link   
	FROM resources r
  		INNER JOIN agent a ON r.agent_id = a.agent_id 
	WHERE a.agent_id ='".$agent_id."'");
	
	$items = mysql_query($query);	
}

$dom = new DomDocument('1.0',"UTF-8");
$dom->formatOutput = true;
$root = $dom->createElement( "results" );
$dom->appendChild( $root );
	while(($item = mysql_fetch_assoc($items)))
	{
		$dn = $dom->createElement( "record" );
		$dn->setAttribute( 'agent_id', ($item['agent_id']));
		$dn->setAttribute( 'name_short', ($item['name_short']));
		$dn->setAttribute( 'name_full', ($item['name_full']));
		$dn->setAttribute( 'date_start', $item['date_start'] );
		$dn->setAttribute( 'date_end', $item['date_end'] );
		$dn->setAttribute( 'resource_link', $item['resource_link'] );
		$root->appendChild( $dn );
	}		
header( "Content-type: text/xml; charset=UTF-8");
echo $dom->saveXML();

?>